#博客详情页
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from common.Utils import BlogDriver

class BlogDetail:
    url=""
    driver=""
    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_detail.html?blogId=139882"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    def DetailTestByLogin(self):
        """
        测试博客详情页
        :return:
        """
        print("----测试博客详情页是否显示正常---")

        #检查标题
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.title")
        #检查时间
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.date")
        #检查内容
        self.driver.find_element(By.CSS_SELECTOR,"#detail")

        #添加显示等待
        WebDriverWait(self.driver, 20).until(EC.text_to_be_present_in_element((By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)"),"文章"))
        # 添加屏幕截图
        BlogDriver.SaveScreenCut(name=type(self).__name__)
        title = self.driver.title
        print("显示正常，当前页面：",title)
        print("----测试结束----\n")

    def DetailTestByNotlogged(self):
        """
        测试未登录状态下进入博客详情页
        :return:
        """
        print("----测试未登录状态下，进入博客详情页----")
        #先注销后打开网址
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)").click()
        self.driver.get("http://8.137.19.140:9090/blog_detail.html?blogId=139868")

        #添加显示等待
        WebDriverWait(self.driver, 20).until(EC.title_is("博客登陆页"))

        title = self.driver.title
        print("当前返回页面："+title)

        # 添加屏幕截图
        BlogDriver.SaveScreenCut(name=type(self).__name__)
        print("----测试结束----\n")